<template>
	<view :class="['dhcc-base', themeName]">
		<!-- 背景 -->
		<view class="dhcc-mine-page-bg"></view>
		<!-- 头部 -->
		<view class="dhcc-mine-page-title-wrap">
			<view class="dhcc-mine-page-title-left">
				<view class="dhcc-flex">
					<image class="dhcc-mine-page-header" :src="userInfo.avatarUrl || '/static/images/R-C.png'" />
					<view>
						<view>{{ userInfo.nickName || '用户昵称' }}</view>
						<view class="dhcc-mine-page-title-info">{{ userInfo.gender || '性别' }}</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 添加用户信息卡片 -->
		<view class="user-info-card">
			<view class="info-item">
				<text class="info-label">角色</text>
				<!-- <text class="info-value">{{ userInfo.country+userInfo.province+userInfo.city || '未知' }}</text> -->
				<text class="info-value">{{ userInfo.country || '未知' }}</text>
			</view>
		</view>

		<!-- 退出登录按钮移至下方 -->
		<view class="logout-section">
			<button class="logout-btn" @click="logout">退出登录</button>
			<!-- <button open-type="contact" class="logout-btn" bindcontact="handleContact">在线客服</button> -->
		</view>
	</view>
</template>

<script>
	import tokenCache from '@/request/token/tokenCache'
	import showModal from '@/utils/showModalHandler'

	export default {
		data() {
			return {
				userInfo: {
					avatarUrl: '',
					nickName: '',
					gender: '',
					country: '',
					province: '',
					city: ''
				}
			}
		},
		methods: {
			logout() {
				uni.showModal({
					title: '提示',
					content: '确定要退出登录吗？',
					success: (res) => {
						if (res.confirm) {
							// 退出登录逻辑
							tokenCache.remove();
							showModal.showToast('退出登录成功');
							uni.reLaunch({
								url: '/pages/loginPage/loginPage'
							});
						}
					}
				});
			},
			handleContact(e) {
				console.log('客服会话状态：', e.detail.errMsg);

				if (e.detail.errMsg === 'contact:ok') {
					console.log('用户成功进入并结束了客服会话');
					// 可以在这里做一些后续处理，比如弹出评价提示
					uni.showToast({
						title: '如有其他问题，欢迎再次咨询',
						icon: 'none'
					});
				} else if (e.detail.errMsg.includes('cancel')) {
					console.log('用户取消了客服会话');
				}
			}
		},
		onLoad() {
			// 页面加载时获取用户信息
			let token = tokenCache.get()
			this.userInfo.nickName = token.authToken.realName
			if (token.authToken.sex == 1) {
				this.userInfo.gender = "男"
			} else if (token.authToken.sex == 2) {
				this.userInfo.gender = "女"
			}
			this.userInfo.country = token.authToken.roleName

		}
	}
</script>

<style>
	.dhcc-base {
		padding-bottom: 150rpx;
	}

	.dhcc-mine-page-bg {
		background-color: var(--dhcc-main-color);
		height: 180rpx;
		border-radius: 0 0 10% 10%;
	}

	.dhcc-mine-page-bg-top {
		display: flex;
		justify-content: flex-end;
		align-items: center;
		padding: var(--padding-small);
	}

	.dhcc-mine-page-bg-top-icon {
		color: var(--dhcc-con-color);
		font-size: var(--font-size-title-second);
	}

	.dhcc-mine-page-title-wrap {
		margin: -100rpx var(--padding-small) 0;
		border-radius: var(--border-radius-large);
		background-color: var(--dhcc-con-back);
		padding: var(--padding-large) var(--padding-small);
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.dhcc-mine-page-title-left {
		font-size: var(--font-size-title-small);
		color: var(--dhcc-title-color);
		font-weight: bold;
	}

	.dhcc-mine-page-header {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
		background-color: var(--dhcc-border-color);
		margin-right: var(--padding-small);
	}

	.dhcc-mine-page-title-info {
		color: var(--dhcc-text-color);
		font-size: var(--font-size-text-minimum);
		margin-top: 10rpx;
	}

	.dhcc-mine-page-title-right {
		font-size: var(--font-size-title-second);
	}

	.dhcc-mine-page-icon {
		margin-left: var(--padding-small);
	}

	.dhcc-list-wrap {
		padding: var(--padding-small);
	}

	.dhcc-icon-medium {
		background-color: var(--dhcc-border-color);
		border-radius: var(--border-radius-medium);
	}

	.dhcc-tabbar-icon {
		background-color: var(--dhcc-border-color);
		border-radius: var(--border-radius-small);
	}

	.dhcc-tabbar-item.active .dhcc-tabbar-icon {
		background-color: var(--dhcc-main-color);
	}

	.dhcc-tabbar-wrap {
		padding-bottom: 50rpx;
		background-color: var(--dhcc-con-back);
	}

	/* 用户信息卡片样式 */
	.user-info-card {
		background-color: var(--dhcc-con-back);
		border-radius: var(--border-radius-large);
		padding: var(--padding-large);
		margin: var(--padding-small);
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
	}

	.info-item {
		display: flex;
		justify-content: space-between;
		padding: 15rpx 0;
		border-bottom: 1rpx solid var(--dhcc-border-color);
	}

	.info-item:last-child {
		border-bottom: none;
	}

	.info-label {
		color: var(--dhcc-text-color);
		font-size: var(--font-size-text);
	}

	.info-value {
		color: var(--dhcc-title-color);
		font-size: var(--font-size-text);
		font-weight: 500;
	}

	/* 退出登录区域样式 */
	.logout-section {
		display: flex;
		justify-content: center;
		margin: var(--padding-large);
	}

	/* 优化退出按钮样式 */
	.logout-btn {
		background-color: var(--dhcc-main-color);
		color: white;
		border: none;
		padding: 12rpx 30rpx;
		border-radius: 30rpx;
		font-size: 28rpx;
		width: 200rpx;
		height: 60rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.1);
		transition: all 0.3s ease;
	}

	.logout-btn:hover {
		opacity: 0.9;
		transform: translateY(-2rpx);
		box-shadow: 0 6rpx 15rpx rgba(0, 0, 0, 0.15);
	}
</style>